package com.dragon.datastructure.stack;

/**
 * 操作符
 *
 * @author dragon
 * @since 2019/12/20
 */
public enum Operator {

    /**
     * 加号
     */
    PLUS("+", 0),

    /**
     * 减号
     */
    MINUS("-", 0),

    /**
     * 乘号
     */
    MULTIPLE("*", 1),

    /**
     * 除号
     */
    DIVIDE("/", 1);

    private String operator;

    private int priority;


    Operator(String operator, int priority) {
        this.operator = operator;
        this.priority = priority;
    }

    /**
     * 通过操作符找到对应的优先级
     *
     * @param operator 操作符
     * @return 优先级
     */
    public static int getPriority(String operator) {
        if (operator == null || "".equals(operator.trim())) {
            return -1;
        }
        Operator[] operatorArray = values();
        for (Operator operatorItem : operatorArray) {
            if (operatorItem.operator.equals(operator)) {
                return operatorItem.priority;
            }
        }

        return -1;
    }

}
